libxl: Do not SEGV when no 'removable' disk parameter in xenstore
authorMarek Marczykowski <marmarek@mimuw.edu.pl>
Mon, 27 Jun 2011 16:37:12 +0000 (17:37 +0100)
committerMarek Marczykowski <marmarek@mimuw.edu.pl>
Mon, 27 Jun 2011 16:37:12 +0000 (17:37 +0100)
Just assume disk as not removable when no 'removable' paremeter

Signed-off-by: Marek Marczykowski <marmarek@mimuw.edu.pl>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c

index 2d61e0b7bb832aed73294ed38e2e2bc748976cad..abba45ee6817acb0d9cb645081a4c8731251e28e 100644 (file)
@@ -1571,6 +1571,7 @@ static unsigned int libxl__append_disk_list_of_type(libxl__gc *gc,
                              libxl__xs_get_dompath(gc, 0), type, domid);
     dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
     if (dir) {
+        char *removable;
         *disks = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
         pdisk = *disks + *ndisks;
         *ndisks += n;
@@ -1588,7 +1589,12 @@ static unsigned int libxl__append_disk_list_of_type(libxl__gc *gc,
                 libxl__sprintf(gc, "%s/%s/type", be_path, *dir)), 
                 &(pdisk->backend));
             pdisk->vdev = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/dev", be_path, *dir), &len);
-            pdisk->removable = atoi(libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s/removable", be_path, *dir)));
+            removable = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
+                                       (gc, "%s/%s/removable", be_path, *dir));
+            if (removable)
+                pdisk->removable = atoi(removable);
+            else
+                pdisk->removable = 0;
             if (!strcmp(libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s/mode", be_path, *dir)), "w"))
                 pdisk->readwrite = 1;
             else